<template>
  <div class="pad-20 bgc-default">
    <div class="pad-20 bg-color-white">

      <!--顶部搜索 -->
      <div class="top-operate mar-t-20">
        <div class="search-item">
          <label>商品搜索：</label>
          <el-select class="select-class" v-model="searchListQuery.searchType" style="width: 120px">
            <el-option label="商品名称" value="title"></el-option>
          </el-select>
          <el-input @keyup.enter.native="handleSearch" v-model="searchListQuery.keyword" placeholder="请输入关键词">
          </el-input>
          <label class="mar-l-20">商品分类：</label>
          <el-cascader v-model="categoryIds" :props="{ checkStrictly: true }" change-on-select placeholder="选择商品分类"
            :options="categoryData" class="special-input" clearable></el-cascader>
          <el-button-group class="mar-l-20">
            <el-button type="primary" @click="handleSearch">查询</el-button>
            <el-button plain @click="resetSearch">重置</el-button>
          </el-button-group>
        </div>
      </div>
      <!--商品状态 -->
      <div class="tabs-box mar-t-15">
        <el-tabs type="card" v-model="searchListQuery.searchGoodsStatus" @tab-click="goodsStatusClick">
          <el-tab-pane :label="allTotalGoodsNumLabel" name="0"></el-tab-pane>
          <el-tab-pane :label="putShelfTotalGoodsNumLabel" name="1"></el-tab-pane>
          <el-tab-pane :label="soldOutTotalGoodsNumLabel" name="2"></el-tab-pane>
          <el-tab-pane :label="offShelfTotalGoodsNumLabel" name="3"></el-tab-pane>
        </el-tabs>
      </div>


      <!-- 内容列表 -->
      <div class="table-container">
        <!-- @selection-change="handleSelectionChange" -->
        <el-table ref="multipleTable" :data="goodsList" v-loading="listLoading" element-loading-text="加载中"
          style="width: 100%">
          <el-table-column label="商品名称" fixed width="320">
            <template slot-scope="scope">
              <div class="flex v-align-c cursor-p mar-r-30">
                <label><img :src="scope.row.imageUrl" class="user-avatar cursor-p"></label>
                <div class="font-14 pad-l-10 v-align-h height-75">
                  <div class="goods-title">
                    <div class="line-2">
                      <el-tag size="mini" v-if="scope.row.skuFlag == 1" type="danger" effect="light">多</el-tag>
                      {{scope.row.title}}
                    </div>
                  </div>
                  <div class="category-style line-2" v-if="scope.row.categoryName">[{{scope.row.categoryName}}]</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="序号" prop="sortNo">
            <template slot-scope="scope">
              <div v-if="editGoodsSortNoIdList.indexOf(scope.row.goodsId) > -1">
                <el-input v-model="scope.row.sortNo" style="width: 80px;"
                  @keyup.native="scope.row.sortNo = checkInputNumWithPoint(scope.row.sortNo, 0)">
                </el-input>
              </div>
              <div v-if="editGoodsSortNoIdList.indexOf(scope.row.goodsId) === -1">
                <span v-if="scope.row.sortNo">{{scope.row.sortNo}}</span>
                <span v-else>0</span>
                <el-button icon="el-icon-edit" type="text" @click="editGoods(3,scope.row.goodsId)">
                </el-button>
              </div>
              <div v-if="editGoodsSortNoIdList.indexOf(scope.row.goodsId) > -1" style="margin-top: 5px;">
                <el-button size="mini" @click="cancelEditGoods(3,scope.row.goodsId)">取消</el-button>
                <el-button type="primary" size="mini" @click="submitEditGoods(3,scope.row)">确定</el-button>
              </div>
            </template>
          </el-table-column>
          <!--          <el-table-column width="50px" type="selection"></el-table-column> -->
          <el-table-column label="库存">
            <template slot-scope="scope">
              <div>总库存： <span v-if="scope.row.stock">{{scope.row.stock}}</span>
                <span v-else>0</span>
              </div>
              <div v-if="editGoodsStockIdList.indexOf(scope.row.goodsId) > -1">
                可用库存： <el-input v-model="scope.row.remainStock" style="width: 80px;" maxlength="8"
                  @keyup.native="scope.row.remainStock = checkInputNumWithPoint(scope.row.remainStock, 0)">
                </el-input>
              </div>
              <div v-if="editGoodsStockIdList.indexOf(scope.row.goodsId) === -1">
                可用库存： <span v-if="scope.row.remainStock">{{scope.row.remainStock}}</span>
                <span v-else>0</span>
                <el-button icon="el-icon-edit" type="text" @click="editGoods(2,scope.row.goodsId)">
                </el-button>
              </div>
              <div v-if="editGoodsStockIdList.indexOf(scope.row.goodsId) > -1" style="margin-top: 5px;">
                <el-button size="mini" @click="cancelEditGoods(2,scope.row.goodsId)">取消</el-button>
                <el-button type="primary" size="mini" @click="submitEditGoods(2,scope.row)">确定</el-button>
              </div>
              <div>占用库存： <span v-if="scope.row.stockInUse">{{scope.row.stockInUse}}</span>
                <span v-else>0</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="限购" prop="sellPrice">
            <template slot-scope="scope">
              <div>
                <div class="flex" style="align-items: center;">
                  <span v-if="scope.row.isGoodsLimit == 0">不限购</span>
                  <span v-else-if="scope.row.isGoodsLimit == 1 && scope.row.limitType == '1'">单笔限购</span>
                  <span v-else>每人限购</span>
                  <div>
                    <el-popover width="650" label-width="170px" trigger="click" placement="top"
                      v-model="scope.row.limitCheckedLable">
                      <el-button slot="reference" icon="el-icon-edit" style="border: none !important;" type="text"
                        @click="scope.row.limitCheckedLable = !scope.row.limitCheckedLable"></el-button>
                      <div>
                        <el-checkbox v-model="scope.row.form.isGoodsLimit">限制每人可购买数量</el-checkbox>
                      </div>
                      <div v-if="scope.row.form.isGoodsLimit">
                        <div>
                          <el-radio v-model="scope.row.form.limitType" label="1">单笔限购</el-radio>
                          <div style="background:#F2F2F6;width:600px" class="pad-10 mar-l-24">
                            <div>
                              <span>每笔订单限购</span>
                              <el-input type="text" class="width-100 mar-l-10 mar-r-10" maxlength="10"
                                v-model="scope.row.form.singleLimitNum"
                                @keyup.native="scope.row.form.singleLimitNum = checkInputNum(scope.row.form.singleLimitNum)">
                              </el-input>
                              <span>件</span>
                            </div>
                            <span>在云店小程序限制顾客购买该商品的每笔订单数量，填空或填0则为不限数量</span>
                          </div>
                        </div>
                        <div>
                          <el-radio v-model="scope.row.form.limitType" label="2">每人限购</el-radio>
                          <div style="background:#F2F2F6;width:600px" class="pad-10 mar-l-24">
                            <div>
                              <el-select v-model="scope.row.form.personLimitType" class="width-150 mar-l-10 mar-r-10"
                                placeholder="请选择">
                                <el-option v-for="item in personLimitList" :key="item.value" :label="item.label"
                                  :value="item.value">
                                </el-option>
                              </el-select>
                              <span>限购</span>
                              <el-input type="text" class="width-100 mar-l-10 mar-r-10" maxlength="10"
                                v-model="scope.row.form.personLimitNum"
                                @keyup.native="scope.row.form.personLimitNum = checkInputNum(scope.row.form.personLimitNum)">
                              </el-input>
                              <span>件</span>
                              <el-tooltip class="item" effect="light" placement="right">
                                <div slot="content">
                                  限购周期说明:<br />
                                  终身限购时限为商品存在的整个时段;<br />
                                  每年限购周期为每年第一天的00:00:00至每年最后一天的23:59:59<br />
                                  每月限购周期为每月第一天的00:00:00至每月最后一天的23:59:59<br />
                                  每周限购周期为周一00:00:00至周天23:59:59<br />
                                  每天限购周期为当天00:00:00至当天23:59:59
                                </div>
                                <i class="el-icon-question"></i>
                              </el-tooltip>
                            </div>
                            <span>限购周期以自然周期计算,如每周从周一到周日计算,其他周期同理;变更限购周期后,系统将重新累计用户已购数</span>
                          </div>
                        </div>
                      </div>
                      <div style="min-height: 210px;" v-else></div>
                      <div class="mar-t-10 flex-center">
                        <el-button @click="limitCancel(scope.row)">取消</el-button>
                        <el-button type="primary" @click="limitConfirm(scope.row)">确定</el-button>
                      </div>
                    </el-popover>
                  </div>
                </div>

              </div>
              <div v-if="scope.row.isGoodsLimit == 1">
                <div v-if="scope.row.limitType == '2'">
                  <span v-if="scope.row.personLimitType == '1'">每天限购{{scope.row.singleLimitNum}}件</span>
                  <span v-if="scope.row.personLimitType == '2'">每周限购{{scope.row.singleLimitNum}}件</span>
                  <span v-if="scope.row.personLimitType == '3'">每月限购{{scope.row.singleLimitNum}}件</span>
                  <span v-if="scope.row.personLimitType == '4'">每年限购{{scope.row.singleLimitNum}}件</span>
                  <span v-if="scope.row.personLimitType == '5'">终身限购{{scope.row.singleLimitNum}}件</span>
                </div>
                <div v-else>
                  <span>{{scope.row.singleLimitNum}}件</span>
                </div>
              </div>

            </template>
          </el-table-column>
          <el-table-column label="零售价" prop="sellPrice">
            <template slot-scope="scope">
              <div v-if="editGoodsPriceIdList.indexOf(scope.row.goodsId) > -1">
                <el-input-number :precision="2" style="width: 80px;" v-model="scope.row.sellPrice" :min="0"
                  :controls="false">
                </el-input-number>
              </div>
              <div v-if="editGoodsPriceIdList.indexOf(scope.row.goodsId) === -1">
                <span v-if="scope.row.sellPrice">￥{{scope.row.sellPrice}}</span>
                <span v-else>----</span>
                <el-button icon="el-icon-edit" type="text" @click="editGoods(1,scope.row.goodsId)"></el-button>
              </div>
              <div v-if="editGoodsPriceIdList.indexOf(scope.row.goodsId) > -1" style="margin-top: 5px;">
                <el-button size="mini" @click="cancelEditGoods(1,scope.row.goodsId)">取消</el-button>
                <el-button type="primary" size="mini" @click="submitEditGoods(1,scope.row)">确定</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="团长佣金(%)" prop="sellPrice">
            <template slot-scope="scope">
              <div v-if="editGoodsCommanderCommissionRateIdList.indexOf(scope.row.goodsId) > -1">
                <el-input-number :precision="2" style="width: 80px;" v-model="scope.row.commanderCommissionRate"
                  :min="0" :controls="false">
                </el-input-number>
              </div>
              <div v-if="editGoodsCommanderCommissionRateIdList.indexOf(scope.row.goodsId) === -1">
                <span v-if="scope.row.commanderCommissionRate">{{scope.row.commanderCommissionRate}}</span>
                <span v-else>0</span>
                <el-button icon="el-icon-edit" type="text" @click="editGoods(4,scope.row.goodsId)"></el-button>
              </div>
              <div v-if="editGoodsCommanderCommissionRateIdList.indexOf(scope.row.goodsId) > -1"
                style="margin-top: 5px;">
                <el-button size="mini" @click="cancelEditGoods(4,scope.row.goodsId)">取消</el-button>
                <el-button type="primary" size="mini" @click="submitEditGoods(4,scope.row)">确定</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="goodsStatus">
            <template slot-scope="scope">
              <div style="display:inline">
                <el-switch v-model="scope.row.goodsStatus" active-color="#13ce66" inactive-color="#ff4949"
                  @change="submitEditGoods(5,scope.row)" :active-value=1 :inactive-value=0></el-switch>
              </div>
              <div style="display:inline" v-if="scope.row.goodsStatus == 1">已上架</div>
              <div style="display:inline" v-else-if="scope.row.goodsStatus == 0">已下架</div>
              <div style="display:inline" v-if="scope.row.remainStock == 0">(已售罄)</div>
            </template>
          </el-table-column>
          <el-table-column label="定时上下架" prop="timeUploadOrDown">
            <div slot-scope="scope" class="flex-col" style="">
              <div class="flex" style="align-items: center;">
                <el-checkbox v-if="scope.row.goodsStatus == 0" v-model="scope.row.isTimeCheck"
                  @change="isCencel(scope.row)">定时上架</el-checkbox>
                <el-checkbox v-if="scope.row.goodsStatus == 1" v-model="scope.row.isTimeCheck"
                  @change="isCencel(scope.row)">定时下架</el-checkbox>
                <div v-if="scope.row.isTimeCheck">
                  <el-popover placement="top" width="245" trigger="click" v-model="scope.row.timingCheckedLable">
                    <div>
                      <span class="flex width-per-100 mar-b-15 flex-center"
                        v-if="scope.row.goodsStatus == 0">设置定时上架时间</span>
                      <span class="flex width-per-100 mar-b-15 flex-center"
                        v-if="scope.row.goodsStatus == 1">设置定时下架时间</span>
                      <el-date-picker v-model="scope.row.openingTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
                        placeholder="选择日期时间"></el-date-picker>
                      <div class="mar-t-10 flex-center">
                        <el-button @click="cancel(scope.row)">取消</el-button>
                        <el-button type="primary" @click="sureSelect(scope.row)">确定</el-button>
                      </div>
                    </div>
                    <el-button slot="reference" icon="el-icon-edit" style="border: none !important;" type="text"
                      @click="scope.row.timingCheckedLable = !scope.row.timingCheckedLable"></el-button>
                  </el-popover>
                </div>
              </div>
              <div v-if="scope.row.isTimeCheck" class="mar-l-10">
                <span class="font-color-9">{{scope.row.viewOpeningTime}}</span>
              </div>
            </div>
          </el-table-column>
        </el-table>
      </div>
      <!-- 列表分页 -->
      <div class="pagination">
        <pagination v-show="total>0" :total="total" :page.sync="searchListQuery.currentPage"
          :limit.sync="searchListQuery.size" @pagination="initGoodsList" />
      </div>
    </div>
  </div>
</template>

<script>
  import {
    listCountGroupBuyWarehouseGoodsStatusNum,
    updateWarehouseGoodsCommanderCommissionRate
  } from '@/api/warehouse/warehouseGoods.js'
  import {
    getGroupBuyWarehouseInfo
  } from '@/api/warehouse/warehouseInfo.js'
  import {
    pagingPromotionGoods
  } from '@/api/sell/promotion'
  import {
    listGoodsCategory,
    updateGoodsSellPrice,
    updateGoodsStock,
    updateGoodsSortNo,
    upGoods,
    downGoods,
    timingUpOrDownGoods,
    updateGoodsLimit
  } from '@/api/goods/goods'
  import {
    getByEnterpriseId
  } from '@/api/user/enterprise'

  export default {
    components: {

    },
    directives: {

    },
    data() {
      return {
        total: 0,
        multipleSelection: [],
        listLoading: true,
        searchListQuery: {
          enterpriseId: this.getEnterpriseId(),
          currentPage: 1,
          size: 10,
          keyword: '',
          searchType: 'title',
          activityType: 2,
          searchGoodsStatus: '0'
        },
        categoryIds: [],
        goodsList: [],
        // 商品的所有分类json
        categoryData: [],
        // 状态标签集合
        allTotalGoodsNumLabel: '全部（0）',
        putShelfTotalGoodsNumLabel: '已上架（0）',
        offShelfTotalGoodsNumLabel: '已下架（0）',
        soldOutTotalGoodsNumLabel: '已售完（0）',
        editGoodsPriceIdList: [],
        editGoodsStockIdList: [],
        editGoodsSortNoIdList: [],
        editGoodsCommanderCommissionRateIdList: [],
        selGoodsGroupList: [],
        hintVisible: true,
        personLimitList: [{
          value: '5',
          label: '终身'
        }, {
          value: '1',
          label: '每天'
        }, {
          value: '2',
          label: '每周'
        }, {
          value: '3',
          label: '每月'
        }, {
          value: '4',
          label: '每年'
        }]
      }
    },
    // 初始化页面
    created() {
      this.initEnterpriseConfig()
      this.initGoodsList()
      this.listGoodsCategory()
    },
    filters: {
      priceFilter(e) {
        return e.toFixed(2)
      }
    },
    mounted() {},
    methods: {
      initGoodsList() {
        this.listLoading = true
        this.searchListQuery[this.textCol] = this.keyword
        this.searchListQuery['oneCategoryId'] = ''
        this.searchListQuery['twoCategoryId'] = ''
        this.searchListQuery['threeCategoryId'] = ''
        const categoryIds = this.categoryIds

        if (categoryIds.length === 1) {
          this.searchListQuery['oneCategoryId'] = categoryIds[0]
        }
        if (categoryIds.length === 2) {
          this.searchListQuery['twoCategoryId'] = categoryIds[1]
        }
        if (categoryIds.length === 3) {
          this.searchListQuery['threeCategoryId'] = categoryIds[2]
        }
        pagingPromotionGoods(this.searchListQuery).then(response => {
          this.total = response.total
          var dataList = response.records
          for (let i = 0; i < dataList.length; i++) {
            // 限购
            dataList[i].limitCheckedLable = false
            dataList[i].form = {}
            dataList[i].form.isGoodsLimit = false
            if (dataList[i].isGoodsLimit === 1) {
              dataList[i].form.isGoodsLimit = true
              dataList[i].form.limitType = dataList[i].limitType + ''
              dataList[i].limitType = dataList[i].limitType + ''
              if (dataList[i].limitType === '2') {
                dataList[i].form.singleLimitNum = 0
                dataList[i].form.personLimitType = dataList[i].personLimitType + ''
                dataList[i].form.personLimitNum = dataList[i].singleLimitNum
              } else { // 单笔限购
                dataList[i].form.personLimitType = '5'
                dataList[i].form.personLimitNum = 0
                dataList[i].form.singleLimitNum = dataList[i].singleLimitNum
              }
            } else {
              // 不限购时 初始化值(默认单笔限购，数量0)
              dataList[i].form.limitType = '1'
              dataList[i].form.singleLimitNum = 0
              dataList[i].form.personLimitType = '5'
              dataList[i].form.personLimitNum = 0
            }
            // 定时上下架
            dataList[i].timingCheckedLable = false
            dataList[i].isTimeCheck = false
            dataList[i].viewOpeningTime = dataList[i].openingTime
            if (dataList[i].isGoodsTiming === 1) {
              dataList[i].isTimeCheck = true
              // if (dataList[i].timeUploadOrDown === 0) {
              //   // 定时执行完成
              //   if (dataList[i].goodsStatus === 0) {
              //     dataList[i].openingTime = ''
              //     dataList[i].viewOpeningTime = ''
              //   } else {
              //     dataList[i].isTimeCheck = true
              //   }
              // } else if (dataList[i].timeUploadOrDown === 1) {
              //   if (dataList[i].goodsStatus === 1) {
              //     dataList[i].openingTime = ''
              //     dataList[i].viewOpeningTime = ''
              //   } else {
              //     dataList[i].isTimeCheck = true
              //   }
              // }
            } else {
              dataList[i].openingTime = ''
              dataList[i].viewOpeningTime = ''
            }
          }
          this.goodsList = dataList
          this.listLoading = false
        })
        listCountGroupBuyWarehouseGoodsStatusNum(this.searchListQuery).then(response => {
          this.allTotalGoodsNumLabel = '全部（' + response.data.allTotalGoodsNum + '）'
          this.putShelfTotalGoodsNumLabel = '已上架（' + response.data.putShelfTotalGoodsNum + '）'
          this.soldOutTotalGoodsNumLabel = '已售完（' + response.data.soldOutTotalGoodsNum + '）'
          this.offShelfTotalGoodsNumLabel = '已下架（' + response.data.offShelfTotalGoodsNum + '）'
        })
      },
      // 获取类目
      listGoodsCategory() {
        const enterpriseId = this.getEnterpriseId()
        listGoodsCategory(enterpriseId).then(response => {
          this.categoryData = response.data
        })
      },
      // 获取系统参数
      initEnterpriseConfig() {
        const enterpriseId = this.getEnterpriseId()
        getByEnterpriseId(enterpriseId).then((response) => {
          if (response.isError) return
          this.enterpriseConfig = response.data
        })
      },
      handleSearch() {
        this.searchListQuery.currentPage = 1
        this.initGoodsList()
      },
      resetSearch() {
        this.searchListQuery.searchType = 'title'
        this.searchListQuery.keyword = ''
        this.searchListQuery.currentPage = '1'
        this.searchListQuery.goodsGroupId = '-1'
        this.categoryIds = []
        this.initGoodsList()
      },
      // 勾选
      handleSelectionChange(val) {
        this.multipleSelection = val
        if (this.multipleSelection.length === this.goodsList.length) {
          this.allChecked = true
        } else {
          this.allChecked = false
        }
      },
      // 商品状态
      goodsStatusClick() {
        this.handleSearch()
      },
      editGoods(type, goodsId) {
        if (type === 1) {
          this.editGoodsPriceIdList.push(goodsId)
        }
        if (type === 2) {
          this.editGoodsStockIdList.push(goodsId)
        }
        if (type === 3) {
          this.editGoodsSortNoIdList.push(goodsId)
        }
        if (type === 4) {
          this.editGoodsCommanderCommissionRateIdList.push(goodsId)
        }
      },
      cancelEditGoods(type, goodsId) {
        if (type === 1) {
          this.editGoodsPriceIdList.some((item, i) => {
            if (item === goodsId) {
              this.editGoodsPriceIdList.splice(i, 1)
              // 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环
              return true
            }
          })
        }
        if (type === 2) {
          this.editGoodsStockIdList.some((item, i) => {
            if (item === goodsId) {
              this.editGoodsStockIdList.splice(i, 1)
              // 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环
              return true
            }
          })
        }
        if (type === 3) {
          this.editGoodsSortNoIdList.some((item, i) => {
            if (item === goodsId) {
              this.editGoodsSortNoIdList.splice(i, 1)
              // 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环
              return true
            }
          })
        }
        if (type === 4) {
          this.editGoodsCommanderCommissionRateIdList.some((item, i) => {
            if (item === goodsId) {
              this.editGoodsCommanderCommissionRateIdList.splice(i, 1)
              // 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环
              return true
            }
          })
        }
      },
      submitEditGoods(type, row) {
        var that = this
        const params = {}
        params.goodsId = row.goodsId
        // 更新价格
        if (type === 1) {
          params.sellPrice = row.sellPrice
          updateGoodsSellPrice(params).then(response => {
            if (response.isError) return
            that.cancelEditGoods(type, row.goodsId)
            that.msgSuccess(response.msg)
          })
        }
        // 更新库存
        if (type === 2) {
          params.stock = row.remainStock
          if (row.stockInUse && row.stockInUse > 0) {
            params.stock = parseInt(params.stock) + parseInt(row.stockInUse)
          }
          updateGoodsStock(params).then(response => {
            if (response.isError) return
            row.stock = params.stock
            that.cancelEditGoods(type, row.goodsId)
            that.msgSuccess(response.msg)
          })
        }
        // 根据商品ID更新商品序号
        if (type === 3) {
          params.sortNo = row.sortNo
          updateGoodsSortNo(params).then(response => {
            if (response.isError) {
              return
            }
            that.cancelEditGoods(type, row.goodsId)
            that.initGoodsList()
            that.msgSuccess(response.msg)
          })
        }
        // 更新团长佣金比例
        if (type === 4) {
          params.warehouseGoodsId = row.warehouseGoodsId
          params.commanderCommissionRate = row.commanderCommissionRate
          updateWarehouseGoodsCommanderCommissionRate(params).then(response => {
            if (response.isError) {
              return
            }
            that.cancelEditGoods(type, row.goodsId)
            that.initGoodsList()
            that.msgSuccess(response.msg)
          })
        }
        // 更新上下架状态
        if (type === 5) {
          const goodsId = row.goodsId
          if (row.goodsStatus === 1) {
            upGoods(goodsId, 30).then(response => {
              if (response.isError) {
                row.goodsStatus = row.goodsStatus === 0 ? 1 : 0
                return
              }
              that.initGoodsList()
              that.msgSuccess(response.msg)
            })
          }
          if (row.goodsStatus === 0) {
            downGoods(goodsId, 30).then(response => {
              if (response.isError) {
                row.goodsStatus = row.goodsStatus === 0 ? 1 : 0
                return
              }
              that.initGoodsList()
              that.msgSuccess(response.msg)
            })
          }
        }
      },
      linkGroupBuyWarehouse() {
        const params = {}
        params.enterpriseId = this.getEnterpriseId()
        getGroupBuyWarehouseInfo(params).then(response => {
          if (response.isError) {
            return
          }
          const warehouseInfoList = response.data
          if (warehouseInfoList === null || warehouseInfoList === undefined) {
            this.msgError('未检测到第三方团购仓，无法直接进入')
            return
          }
          if (warehouseInfoList.length === 0) {
            this.msgError('未检测到第三方团购仓，无法直接进入')
            return
          }
          if (warehouseInfoList.length > 1) {
            this.msgError('存在多个第三方团购仓无法直接进入')
            return
          }
          this.$router.push({
            path: '/warehouse/warehouse-authorize-goods/index',
            query: {
              warehouseId: warehouseInfoList[0].warehouseId,
              authorizeType: 1
            }
          })
        })
      },
      closeHint() {
        this.hintVisible = false
      },
      sureSelect(row) {
        var that = this
        if (!row.openingTime) {
          this.$message({
            type: 'error',
            message: '请选择定时上下架时间！'
          })
          return false
        }
        const nowTime = new Date().getTime()
        if ((nowTime + 300000) > new Date(row.openingTime).getTime()) {
          return this.$message({
            type: 'error',
            message: '开启时间必须大于当前时间5分钟'
          })
        }
        const isGoodsTiming = 1
        const timeUploadOrDown = row.goodsStatus === 0 ? 1 : 0
        timingUpOrDownGoods(row.goodsId, timeUploadOrDown, row.openingTime, isGoodsTiming).then((response) => {
          if (response.isError) return
          row.viewOpeningTime = row.openingTime
          row.timingCheckedLable = false
          that.initGoodsList()
        })
      },
      cancel(row) {
        row.timingCheckedLable = false
      },
      // 取消定时上下架
      isCencel(row) {
        const isGoodsTiming = 0
        if (!row.isTimeCheck && row.viewOpeningTime) {
          timingUpOrDownGoods(row.goodsId, null, null, isGoodsTiming).then((response) => {
            if (response.isError) return
            row.viewOpeningTime = ''
            row.openingTime = ''
            this.initGoodsList()
          })
        }
      },
      limitConfirm(row) {
        let isGoodsLimit = 0
        if (row.form.isGoodsLimit) {
          isGoodsLimit = 1
          const limitType = row.form.limitType
          let singleLimitNum
          let personLimitType
          if (limitType === '1') {
            singleLimitNum = row.form.singleLimitNum
          } else {
            singleLimitNum = row.form.personLimitNum
            personLimitType = row.form.personLimitType
          }
          updateGoodsLimit(row.goodsId, limitType, personLimitType, singleLimitNum, isGoodsLimit).then((response) => {
            if (response.isError) return
            this.limitCancel(row)
            this.initGoodsList()
          })
        } else {
          updateGoodsLimit(row.goodsId, null, null, null, isGoodsLimit).then((response) => {
            if (response.isError) return
            this.limitCancel(row)
            this.initGoodsList()
          })
        }
      },
      limitCancel(row) {
        row.limitCheckedLable = false
      }
    }
  }
</script>
<style lang="less" scoped>
  .top-operate {
    margin-bottom: 0;
    height: 85px;
    background-color: #f7f8fa;
    display: flex;
    align-items: center;
    white-space: nowrap;
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
  }

  .search-item {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 0 20px;

    label {
      font-weight: unset;
    }

    >div,
    .el-cascader {
      margin-right: 0px;
    }

    .el-input {
      width: 200px;
    }
  }

  .btn-search {
    height: 60px;
    display: flex;
    align-items: center;
  }

  .user-avatar {
    width: 65px;
    height: 65px;
    display: block;
    padding: 1px;
    border: #efefef 1px solid;
  }

  .category-style {
    color: #636669;
  }

  .v-align-h {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
  }

  .goods-title {
    color: #155bd4;
    line-height: 1.2;
  }

  // 2行文字展示
  .line-2 {
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
  }

  .hint-area {
    background-color: #fdf8c8;
    height: 45px;
    line-height: 45px;

    .hint-icon {
      padding: 1px;
      margin: 10px 10px 0 0;
    }
  }
</style>
